<template>
  <div class="ticket">
    <SearchCom class="search_box" @searchEvent="searchEvent" placeholder="搜索工单信息" />
    <!-- <van-list
      v-model:loading="loading"
      :finished="finished"
      :offset="48"
      class="ticket_box"
      finished-text="没有更多了"
      @load="onLoad"
    > -->
    <template v-if="planList.length > 0">
      <TicketItem
        v-for="item in planList"
        :key="item.id"
        :data="item"
        @handleClick="handleClick"
      />
    </template>
    <van-empty v-else description="暂无工单" />

    <!-- </van-list> -->
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { getOrderList, getCurrentUserList } from '@/api/workOrder.js';
const router = useRouter();
import TicketItem from '@/components/ticketItem.vue';

const planList = ref([]);
const total = ref(0);
const searchData = reactive({
  // pageNumber: 1,
  // pageSize: 10,
  // deviceType: '',
  // exceptionType: '',
  // startTime: '',
  // endTime: '',
  // state: '',
  // keywords: '',
  //
  deviceName: '',
});
const loading = ref(false);
const finished = ref(false);
// const onLoad = () => {
//   setTimeout(async () => {
//     loading.value = true;
//     await getList();
//     searchData.pageNumber++;
//   }, 500);
// };

onMounted(() => {
  getList();
});

function getList() {
  // getOrderList(searchData)
  getCurrentUserList(searchData)
    .then((res) => {
      // total.value = res.data.total || 0;
      if (res.data) {
        planList.value = res.data || [];
        // loading.value = false;
        // if (planList.value.length >= total.value) {
        //   finished.value = true;
        // }
      } /*  else {
          planList.value = [];
          finished.value = true;
        } */
    })
    .catch((err) => {
      console.log('err', err);
    })
    .finally(() => {
      loading.value = false;
    });
}
function handleClick(data) {
  router.push({ name: 'ticketDetail', params: { id: data.id } });
}

function searchEvent(val) {
  // searchData.keywords = val;
  // searchData.pageNumber = 1;
  // planList.value = [];
  searchData.deviceName = val;
  getList();
}
</script>

<style scoped lang="scss">
.ticket {
  padding: 0 0 48px 0;
  width: 100%;
  height: calc(100vh - 110px);
  overflow-y: hidden;

  .ticket_box {
    height: 100%;
    overflow-y: auto;
  }

  .search_box {
    margin: 16px 0;
  }
}
</style>
